import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.JTextField;

public class Interface_graphique extends JFrame{ 

	private JLabel label1 = new JLabel("Nombre de clients : ");
	public JFormattedTextField jtf1  = new JFormattedTextField("");

	private JLabel label2 = new JLabel("Nombre de Trames : ");
	private JFormattedTextField jtf2  = new JFormattedTextField("");

	private JLabel label3 = new JLabel("Transmission limit : ");
	private JFormattedTextField jtf3  = new JFormattedTextField("");

	private JLabel label4 = new JLabel("Cdma max : ");
	private JFormattedTextField jtf4  = new JFormattedTextField("");
	
	private JLabel label5 = new JLabel("Static Trade-off  (0 = Auto) : ");
	private JFormattedTextField jtf5  = new JFormattedTextField("");
	
	private JLabel label6 = new JLabel("Logging :(0=Inactif - 1=Actif) ");
	private JFormattedTextField jtf6  = new JFormattedTextField("");

	private JButton b = new JButton ("Lancer la Simulation");


	private void set_pref(JFormattedTextField jt){

		Font police = new Font("Arial", Font.BOLD, 10);
		jt.setFont(police);
		jt.setPreferredSize(new Dimension(35, 30));
		jt.setForeground(Color.BLUE);
	}


	public void affiche_fenetre(){

		this.setTitle("Simulateur Wimax");
		this.setSize(800, 200);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationRelativeTo(null);


		this.setBackground(Color.white);

		//GridLayout gl = new GridLayout();

		this.setLayout(new BorderLayout()); 

		JPanel but = new JPanel(); // couple text box et label
		but.add(this.b);


		JPanel top1 = new JPanel(); // couple text box et label
		this.set_pref(jtf1);
		top1.add(label1);
		top1.add(jtf1);


		JPanel top2 = new JPanel();
		this.set_pref(jtf2);
		top2.add(label2);
		top2.add(jtf2);

		JPanel top3 = new JPanel();
		this.set_pref(jtf3);
		top3.add(label3);
		top3.add(jtf3);


		JPanel top4 = new JPanel();
		this.set_pref(jtf4);
		top4.add(label4);
		top4.add(jtf4);
		
		JPanel top5 = new JPanel();
		this.set_pref(jtf5);
		top5.add(label5);
		top5.add(jtf5);
		
		JPanel top6 = new JPanel();
		this.set_pref(jtf6);
		top6.add(label6);
		top6.add(jtf6);
		
		JPanel full = new JPanel();
		JPanel full2 = new JPanel();
		
		full.add(top1);
		full.add(top2);
		full.add(top3);
		full.add(top4);
		
		full2.add(top5);
		full2.add(top6);


		b.addActionListener(new BoutonListener());  
		
		this.getContentPane().add(full, BorderLayout.CENTER);
		this.getContentPane().add(full2, BorderLayout.NORTH);
		
		this.getContentPane().add(but,BorderLayout.SOUTH );

		this.setVisible(true);    
		
		while(Utils.start!=true){
			
			System.out.flush();
			
		}
		this.dispose();

	}
	class BoutonListener implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			
			Utils.feed_program_from_ihm(Integer.parseInt(jtf1.getText()),Integer.parseInt(jtf2.getText()), Integer.parseInt(jtf3.getText()), Integer.parseInt(jtf4.getText()),Integer.parseInt(jtf5.getText()),Integer.parseInt(jtf6.getText())); 
			// feed programme avec l'ihm 

			try {Utils.writeF("Start Simulation.." , "console");} 
			catch (IOException e1) {e1.printStackTrace();}
			////System.out.println("Start Simulation..");
			Utils.start=true;
			//Simulation simu1 = new Simulation();
		}
	}
}
